<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="">
     
      <el-form-item label="车牌号" prop="vehicle.licensePlateNumber">
        <el-input
          v-model="queryParams.chargingId"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付日期" prop="paymentTime">
          <el-date-picker clearable
            v-model="form.issueDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择日期">
          </el-date-picker>
      </el-form-item>
      <el-form-item label="总收费金额" prop="totalMoney">
        <el-input
          v-model="queryParams.totalMoney"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:tollInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序列号" align="center" prop="serialNumber" />
      <el-table-column label="车牌号" align="center" prop="vehicle.licensePlateNumber" />
      <el-table-column label="联系方式" align="center" prop="vehicle.ownerContact" />
      <el-table-column label="劵名称" align="center" prop="coupon.mallName" />
      <el-table-column label="抵用时长" align="center" prop="coupon.duration" />
      <el-table-column label="支付类型" align="center" prop="paymentType" />
      <el-table-column label="支付日期" align="center" prop="paymentTime" />
      <el-table-column label="支付状态" align="center" >
         <template slot-scope="scope">  
    <span>{{ getStatusText(scope.row.paymentStatus) }}</span>  
  </template> 
      </el-table-column>
      <el-table-column label="停车总时长" align="center" prop="totalTime" />
      <el-table-column label="总收费金额" align="center" prop="totalMoney" />
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo } from "@/api/system/tollInfo";

export default {
  name: "Info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 收费管理表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        vehicleId: null,
        chargingId: null,
        parkingId: null,
        paymentType: null,
        paymentTime: null,
        paymentStatus: null,
        totalMoney: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
     getStatusText(status) {  
      switch (status) {  
        case 0:  
          return '待支付中';  
        case 1:  
          return '支付成功';   
        default:  
          return '未知状态';  
      }  
    },  
    /** 查询收费管理列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        tollId: null,
        vehicleId: null,
        chargingId: null,
        parkingId: null,
        paymentType: null,
        paymentTime: null,
        paymentStatus: null,
        totalMoney: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.tollId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加收费管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const tollId = row.tollId || this.ids
      getInfo(tollId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改收费管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.tollId != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const tollIds = row.tollId || this.ids;
      this.$modal.confirm('是否确认删除收费管理编号为"' + tollIds + '"的数据项？').then(function() {
        return delInfo(tollIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/tollInfo/export', {
        ...this.queryParams
      }, `info_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
